package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.DictDTO;
import cn.com.blueInfo.bpm.system.response.DictVO;
import cn.com.blueInfo.bpm.system.service.DictService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 枚举表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "枚举 接口")
@RestController
@RequestMapping("/system/dict")
public class DictController extends BaseController {

    @Autowired
    private DictService dictService;

    /**
     * 新建枚举
     * @param dictDTO 枚举参数
     * @return ResultInfo
     */
    @Operation(summary = "新增枚举")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createDict(
            @Validated({Create.class, Default.class}) @RequestBody DictDTO dictDTO) {
        return dictService.addDict(dictDTO);
    }

    /**
     * 批量新建枚举
     * @param dictDTOList 枚举参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建枚举")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateDict(
            @Validated({Create.class, Default.class}) @RequestBody List<DictDTO> dictDTOList) {
        return dictService.batchAddDict(dictDTOList);
    }

    /**
     * 根据ID删除枚举
     * @param dictId 枚举ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除枚举")
    @DeleteMapping("/removeInfo/{dictId}")
    public ResultInfo<Integer> deleteDictById(
            @Parameter(name = "ID") @PathVariable Long dictId) {
        return dictService.removeDict(dictId);
    }

    /**
     * 批量根据ID删除枚举
     * @param dictIdList 枚举ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除枚举")
    @DeleteMapping("/removeInfoList/{dictIdList}")
    public ResultInfo<Integer> deleteDictById(
            @Parameter(name = "ID") @PathVariable List<Long> dictIdList) {
        return dictService.batchRemoveDict(dictIdList);
    }

    /**
     * 根据ID全量更新枚举
     * @param dictId 枚举ID
     * @param dictDTO 枚举参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新枚举")
    @PutMapping("/modifyInfo/{dictId}")
    public ResultInfo<Integer> updateDictFull(
            @Parameter(name = "ID") @PathVariable Long dictId,
            @Validated({Update.class, Default.class}) @RequestBody DictDTO dictDTO) {
        validateUpdateId(dictId, dictDTO.getId());
        return dictService.modifyDict(dictDTO);
    }

    /**
     * 根据ID部分更新枚举
     * @param dictId 枚举ID
     * @param dictUpdatePartialDTO 枚举参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新枚举")
    @PatchMapping("/modifyPartialInfo/{dictId}")
    public ResultInfo<Integer> updateDictPartial(
            @Parameter(name = "ID") @PathVariable Long dictId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            DictDTO.UpdatePartialDTO dictUpdatePartialDTO) {
        validateUpdateId(dictId, dictUpdatePartialDTO.getId());
        return dictService.modifyDictPartial(dictUpdatePartialDTO);
    }

    /**
     * 根据ID查询枚举
     * @param dictId 枚举ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询枚举")
    @GetMapping("/getInfo/{dictId}")
    public ResultInfo<DictVO> getDictById(
            @Parameter(name = "ID") @PathVariable Long dictId) {
        return dictService.queryDictById(dictId);
    }

    /**
     * 分页查询枚举
     * @param dictQueryDTO 枚举参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询枚举")
    @GetMapping("/getInfos")
    public ResultInfo<Page<DictVO>> getDictPage(
            @Validated DictDTO.QueryDTO dictQueryDTO) {
        return dictService.queryDictPage(dictQueryDTO);
    }

    /**
     * 根据条件查询枚举
     * @param dictQueryDTO 枚举参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询枚举")
    @GetMapping("/getInfoList")
    public ResultInfo<List<DictVO>> getDictList(
            @Validated DictDTO.QueryDTO dictQueryDTO) {
        return dictService.queryDictList(dictQueryDTO);
    }

}
